<?php

namespace App\Http\Controllers\Api\User;

use App\Http\Controllers\ApiController;
use App\Models\Cash;
use App\Models\SystemConfig;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;


class CashController extends ApiController
{
    /**
     * 申请提现
     */
    public function apply_cash(Request $request,Cash $cashModel)
    {
        //从配置文件中取出提现的最小金额限制
        $min_moeny = SystemConfig::getConfValByConfKey('cash_min_money');
        $min_moeny = empty($min_moeny) ? 0 : (int) $min_moeny['conf_val'];
        $validator = Validator::make($request->all(), [
            'money'               => "required|integer|min:$min_moeny",
//            'alipay_account'  => 'required',
//            'phone'           => 'required',
//            'true_name'       => 'required',
            'hotel_open_id' => 'required'
        ],['money.min'=>'提现金额必须大于'.$min_moeny.'元']);

        if($validator->fails()){
            return self::response(null,self::ERROR_CODE,$validator);
        }
        //申请提现操作
        if($cashModel -> api_cash($request->all())){
            return self::response(null,self::SUC_CODE,'申请提现成功');
        }
        return self::response(null,self::ERROR_CODE,Cash::$error);
    }
}
